package com.py.classloader.test;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

/**
 * 类加载器ClassLoader测试
 * 
 * @author cyd
 * @date 2018年5月16日
 */
public class ClassLoaderTestMain {

	public static void main(String[] args) {
		try {
			test1();
			testMainRun();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void testMainRun() throws Exception {
		ClassLoader loader = JarLoader.createClassLoader(ClassLoaderTestMain.class.getClassLoader(), "jar_classloader");
		Class<?> clazz = loader.loadClass("com.py.classloader.test.clazz.Main");
		Runnable main = (Runnable)clazz.newInstance();
		main.run();
	}
	
	public static void test1() throws Exception {
		ClassLoader loader = JarLoader.createClassLoader(ClassLoaderTestMain.class.getClassLoader(), "jar_classloader");
		Class<?> clazz = loader.loadClass("com.py.classloader.test.clazz.TestBean");
		System.out.println(clazz);
		Constructor<?> c = clazz.getConstructor(String.class);
		Object testBean = c.newInstance("lalal");
		System.out.println(testBean);
		Class<?> ubClazz = loader.loadClass("com.py.classloader.test.clazz.TestService");
		Method m = ubClazz.getMethod("getTestBean", String.class);
		System.out.println(m);
		System.out.println(m.invoke(null, "dsafdsafds"));
	}
}
